package com.cs.study.homework._0219;

public class Demo5 {
    public static void main(String[] args) {
        Square square = new Square();
        square.setSideLength(10);
        square.getPerimeter();
        square.getAera();
        Rectangle rectangle = new Rectangle();
        rectangle.setShortSideLength(10);
        rectangle.setLongSideLength(20);
        rectangle.getPerimeter();
        rectangle.getAera();

    }
}

//正方形
class Square {
    //定义边长
    private double sideLength;

    public double getSideLength() {
        return sideLength;
    }

    public void setSideLength(double sideLength) {
        if (sideLength > 0) {
            this.sideLength = sideLength;
        } else {
            System.out.println("输入不合法");
        }
    }

    //计算周长
    public void getPerimeter() {
        double perimeter = sideLength * 4;
        System.out.println("正方形周长=" + perimeter);
    }

    //计算面积
    public void getAera() {
        double area = sideLength * sideLength;
        System.out.println("正方形面积=" + area);
    }
}

//长方形
class Rectangle {
    //定义短边
    private double shortSideLength;
    //定义长边
    private double longSideLength;

    public void setShortSideLength(double shortSideLength) {
        if (shortSideLength > 0) {
            this.shortSideLength = shortSideLength;
        } else {
            System.out.println("输入不合法");
        }
    }

    public void setLongSideLength(double longSideLength) {
        if (longSideLength > 0) {
            this.longSideLength = longSideLength;
        } else {
            System.out.println("输入不合法");
        }
    }

    public double getShortSideLength() {
        return shortSideLength;
    }

    public double getLongSideLength() {
        return longSideLength;
    }

    //计算周长
    public void getPerimeter() {
        double perimeter = shortSideLength * 2 + longSideLength * 2;
        System.out.println("长方形周长=" + perimeter);
    }

    //计算面积
    public void getAera() {
        double area = shortSideLength * longSideLength;
        System.out.println("长方形面积=" + area);
    }
}